<?php

namespace App\Http\Controllers\Chat;


use App\Exceptions\AdminException;
use App\Http\Controllers\AdminBaseController;
use App\Http\Requests\Chat\LoginRequest;
use App\Services\Chat\IndexService;
use App\Services\Chat\User\ChatUserService;
use App\Util\LoginUtil;

class LoginController extends AdminBaseController
{
    protected $services = null;


    public function __construct(IndexService $Services)
    {
        parent::__construct();
        $this->services = $Services;
    }


    //注册
    public function register(LoginRequest $request)
    {
        return $this->success($this->services->register($request));
    }


    //chat登入
    public function chatLogin(LoginRequest $request)
    {
        $key = $request->input('key'); //key
        return $this->success($this->services->chatLogin($request));
    }


    /**
     * 注销登录
     *
     * @return \Illuminate\Http\Response
     */
    public function logout()
    {
        $user = auth()->user();
        if($user){
            $user->is_online = 0;
            $user->save();
        }
        $user->currentAccessToken()->delete();

        return $this->success();
    }
}
